﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using IMModel.Domain;

namespace DataAccessLayer.Admin.Filters
{
    public class InputLogFilterGenerator : FilterGeneratorBase
    {
        private InputLogFilterGenerator() { }
        public static readonly InputLogFilterGenerator I = new InputLogFilterGenerator();

        public Func<InputLog, bool> UserName(string userName, DTO.ConditionTypes ConditionType)
        {
            var param = Expression.Parameter(typeof(InputLog), "UserName");

            var UserName_prop = Expression.Property(param, "UserName");

            var ToLower_method = Expression.Call(UserName_prop,
                typeof(string).GetMethod("ToLower", Type.EmptyTypes));

            Expression resultExpression = Expression.Call(ToLower_method,
                typeof(string).GetMethod("Contains", new Type[] { typeof(string) }), Expression.Constant(userName));
            resultExpression = CheckNotContains(resultExpression, ConditionType);

            var l = Expression.Lambda<Func<InputLog, bool>>(resultExpression, param);

            return l.Compile();
        }
    }
}
